package com.vooda.business_admin.controller.homePage;

import com.vooda.business_admin.common.BaseController;
import com.vooda.business_admin.common.ReqDataTableDto;
import com.vooda.business_admin.common.RspDataTableDto;
import com.vooda.business_admin.entity.Store;
import com.vooda.business_admin.entity.Ticket;
import com.vooda.business_admin.service.StoreService;
import com.vooda.business_admin.service.TicketService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 优惠券
 */
@RestController
@RequestMapping("/ticket")
public class TicketController extends BaseController{

    @Autowired
    private TicketService ticketService;


    /**
     * 获取所有商家列表
     * @param dataTableDTO
     * @return
     */
    @GetMapping("/getAllList")
    public RspDataTableDto<Ticket> getAllList(ReqDataTableDto dataTableDTO,
                                              @RequestParam(value = "market",required = false) String marketId,
                                              @RequestParam(value = "store",required = false) String storeId,
                                              @RequestParam(value = "type",required = false) String typeId,
                                              @RequestParam(value = "happyBag",required = false) String happyBag){

        return ticketService.findAllTicketList(dataTableDTO,marketId,storeId,typeId,happyBag);

    }

    /**
     *查单个优惠券
     * @return
     */
    @GetMapping("/editTicket/{id}")
    public Ticket editTicket(HttpServletRequest request, @PathVariable("id") Long id){
        return ticketService.selectAllInfobyId(id);

    }


    /**
     *查单个优惠券
     * @return
     */
    @PostMapping("/modifyBag/{id}")
    public void modifyBag(HttpServletRequest request, @PathVariable("id") Long id){
         ticketService.modifyBag(id);
    }

    /**
     *保存优惠券
     * @return
     */
    @PostMapping("/saveTicket")
    public String saveTicket(Ticket ticket,String forever){

        return ticketService.saveTicket(ticket,forever);


    }

    /**
     * 删除优惠券
     * @param request
     * @param id
     * @return
     */
    @PostMapping("/removeTicket/{id}")
    public String removeArticle(HttpServletRequest request, @PathVariable("id") Long id){
        return ticketService.deleteByPrimaryKey(id);

    }

    /**
     * 关联的各种查询

     * @return
     */
    @GetMapping("/getCompelexList")
    public Map<String,Object> getCompelexList(){
        return ticketService.getCompelexList();

    }


}
